package com.cyzy.controller;
import com.cyzy.dto.ApiResponse;

import com.cyzy.dto.DanmakuRequest;
import com.cyzy.service.DanmakuService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


import java.io.IOException;
@CrossOrigin
@RestController
@RequestMapping("/api/danmaku")
public class DanmakuController {

    @Resource
    private DanmakuService danmakuService;

    //接收前端弹幕
    @PostMapping("/process")

    public ApiResponse<String> processDanmaku(@Valid @RequestBody DanmakuRequest request) {
        try {
            String result = danmakuService.processDanmaku(request);
            return ApiResponse.success(result);
        } catch (IOException e) {
            return ApiResponse.error("处理弹幕失败: " + e.getMessage());
        }
    }
}
